//package com.woniuxy.commons.consumer;
//
//import com.woniuxy.elderlycare.dao.GoodsMapper;
//import com.woniuxy.elderlycare.dao.GoodsOrderInfoMapper;
//import com.woniuxy.elderlycare.dao.GoodsOrderItemMapper;
//import com.woniuxy.elderlycare.dao.ServiceOrderInfoMapper;
//import com.woniuxy.elderlycare.dto.alipay.PayInfoDto;
//import com.woniuxy.elderlycare.model.ServiceOrderInfo;
//import com.woniuxy.elderlycare.util.AlipayUtil;
//import com.woniuxy.elderlycare.util.StateUtil;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//
//@Component
//@RabbitListener(queues = "serviceOrder_check_queue")
//public class ServiceOrderConsumer {
//    @Autowired
//    private AlipayUtil alipayUtil;
//    @Autowired
//    private GoodsOrderInfoMapper goodsOrderInfoMapper;
//    @Autowired
//    private GoodsOrderItemMapper goodsOrderItemMapper;
//    @Autowired
//    private GoodsMapper goodsMapper;
//    @Resource
//    private ServiceOrderInfoMapper serviceOrderInfoMapper;
//
//
//
//    @RabbitHandler
//    public void handler(String orderNum) throws Exception {
//        PayInfoDto payInfoDto = alipayUtil.queryPayState(orderNum);
//        ServiceOrderInfo serviceOrderInfo = serviceOrderInfoMapper.selectById(orderNum);
//        if (payInfoDto.getPayState().equals("TRADE_SUCCESS")) {
//            if (serviceOrderInfo.getServiceState() == StateUtil.SERVICE_ORDER_NORMAL) {
//                //修改订单状态
//                serviceOrderInfo.setServiceState(StateUtil.SERVICE_ORDER_COMPLETED);
//                //支付时间
//                LocalDateTime localDateTime = LocalDateTime.parse(payInfoDto.getPayDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//                serviceOrderInfo.setServicePayTime(localDateTime);
//                serviceOrderInfoMapper.updateById(serviceOrderInfo);
//            }
//        } else {//未支付
//            serviceOrderInfo.setServiceState(StateUtil.SERVICE_ORDER_CANCEL);
//            serviceOrderInfoMapper.updateById(serviceOrderInfo);
//        }
//    }
//}
